package com.huahua.shard.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huahua.shard.entity.OrderInfo;
import com.huahua.shard.mapper.OrderInfoMapper;

@Service
public class OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    public String add() throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 10; i++) {
            OrderInfo orderInfo = new OrderInfo();
            orderInfo.setId(UUID.randomUUID().toString());
            int a = RandomUtils.nextInt(1, 9);
            String dateStr = "2024-09-1" + a;
            Date date = formatter.parse(dateStr);
            orderInfo.setCreateDate(date);
            orderInfoMapper.insert(orderInfo);

            orderInfo.setId(UUID.randomUUID().toString());
            String dateS = "2024-10-1" + a;
            orderInfo.setCreateDate(formatter.parse(dateS));
            orderInfoMapper.insert(orderInfo);

            orderInfo.setId(UUID.randomUUID().toString());
            String date2S = "2024-11-1" + a;
            orderInfo.setCreateDate(formatter.parse(date2S));
            orderInfoMapper.insert(orderInfo);

            orderInfo.setId(UUID.randomUUID().toString());
            String date22S = "2024-12-1" + a;
            orderInfo.setCreateDate(formatter.parse(date22S));
            orderInfoMapper.insert(orderInfo);

        }
        return "0";
    }

    public Object get() {
        QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
        //wrapper.eq("create_date","2024-08-08");
        return orderInfoMapper.selectList(wrapper);
    }
}
